% Table 7 in "Commodity Prices, Convenience Yields, and Inflation"
% March 2011

clear all;

load ds.dat;                    % changes in spot commodity prices
load cyj.dat;                   % convenience yields on 23 commodities
load us_intrate_monthly.dat;    % US 3-month T-bill rate
load usd_monthly_ave.dat;       % USD trade-weighted index 

i=us_intrate_monthly;
er=usd_monthly_ave;
nn=rows(i);

h=1;             % forecast horizon
nwl=-1;          % number of lags in Newey-West HAC estimator
dx=100*(log(er(3:nn-h,1))-log(er(2:nn-h-1,1)));
ir=i(3:nn-h,1);
const=ones(nn-h-2,1);
cy=[];
for j=1:cols(ds);
    ds_h=ds(3:rows(ds),j);
    ds_1=ds(2:rows(ds)-1,j);
    ds_2=ds(1:rows(ds)-2,j);
    cy(:,j)=cyj(3:nn-h,j);
    x1=[cy(:,j) ir dx ds_1 ds_2 const];
    res=nwest(ds_h,x1,0);
    b=res.beta;
    r=res.resid;
    R2=res.rbar;
    G = nw((r*ones(1,cols(x1))).*x1,-1);
    V=inv(x1'*x1)*G*inv(x1'*x1);
    se = sqrt(diag(V));
    ts = b./se;
    disp([b(1) se(1) b(2) se(2) b(3) se(3) R2])
end;
